package br.ufrj.dcc.comp2.musica.controle;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class ControladorDeSenhas {
	private String entrada;
	private String hash;
	
	public ControladorDeSenhas(String entrada) {
		this.entrada = entrada;
		hash = null;
	}
	
	public String encriptar() {
		if(hash != null) {
			return hash;
		}
		else {
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");
				md.update(entrada.getBytes());
				hash = new String(md.digest());
				
			} catch (NoSuchAlgorithmException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			return hash;
		}
	}
	
	public boolean comparar(String hash) {
		return this.hash.equals(hash);
	}

	public String getEntrada() {
		return entrada;
	}

	public String getHash() {
		return hash;
	}
}
